# conding = utf-8
from selenium.webdriver import ActionChains, Keys

from pages.page import Page
from pages.lyz.pycache.goods import left_menu_sys, left_menu, find_send, find_expected, find_btn, depot_send, \
    depot_btn, btn_unfold, category_send, category_btn, zero_send, zero_btn, \
    pipelining, pipelining_send, pipelining_btn, reset, time_btn, time_element, time_left, time_begin, time_end, \
    pipelining_detail, pipelining_cancel
import time


class GoodsPage(Page):
    '''
    报表查询--商品库存
    '''

    # 查询UI测试

    def open_sales_order(self):
        '''
        打开管理员UI，如果已经打开则不会执行单击动作
        :return:
        '''
        if self.display(left_menu) is False:  # 如果是隐藏状态则单击
            self.click(left_menu_sys)
        self.click(left_menu)

    def btn_unfold(self):
        self.click(btn_unfold)

    def depot_send(self):
        self.click(depot_send)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.UP)
        actions.send_keys(Keys.UP)
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def search_input(self, value):
        self.send_keys(find_send, value)

    def category_send(self):
        self.click(category_send)
        time.sleep(1)

    def category_btn(self):
        self.click(category_btn)

    def find_btn(self):
        self.click(find_btn)

    def search_result_text(self):
        '''
        单击查找完成后，获取查找结果
        :return:
        '''
        return self.text(find_expected)

    # 显示零库存的商品
    def zero_send(self):
        self.click(zero_send)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        time.sleep(1)
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    # 库存流水界面的查询、查看
    def pipelining(self):
        # 进入库存流水界面
        self.click(pipelining)
        time.sleep(1)

    def pipelining_send(self):
        self.send_keys(pipelining_send, 'CXD00000000642')
        time.sleep(1)

    def pipelining_btn(self):
        self.click(pipelining_btn)
        time.sleep(1)

    def reset(self):
        self.click(reset)
        time.sleep(2)

    def time_btn(self):
        self.click(time_btn)
        time.sleep(1)

    def time_left(self):
        self.click(time_left)
        time.sleep(1)

    def time_begin(self):
        self.click(time_begin)
        time.sleep(1)

    def time_end(self):
        self.click(time_end)
        time.sleep(1)

    # def pipelining_btn(self):
        # self.click(pipelining_btn)

    # def reset(self):
        # self.click(reset)

    def time_element(self):
        self.click(time_element)
        time.sleep(1)

    def pipelining_detail(self):
        self.click(pipelining_detail)
        time.sleep(1)

    def pipelining_cancel(self):
        self.click(pipelining_cancel)
        time.sleep(1)
